<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src="jq/jQuery.js"></script>
	<style>
		*{
			padding: 0px;
			margin: 0px;
			list-style: none;
		}
		#box{
            max-width: 950px;
            margin: 30px auto;
            padding: 20px;
            height: 700px;
        }
        #titleOfPay {
            text-align: center;
            margin-bottom: 55px;
        }
        #titleOfPay h1 {
            color: #4a6bff;
            margin-bottom: 10px;
        }
        .bodyOfPay{
        	background: white;
            padding: 25px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            float: left;
        }
        .orderTitle{
        	display: block;
        	margin-bottom: 20px;
        	margin-top: 20px;
        }
        .typeOfInput{
        	font-weight: 600;
        }
        .inputOfValue{
        	width: 450px;
        	height: 30px;
        	display: inline-block;
        	border: 1px solid rgba(0, 0, 0, 0.1);
        	border-radius: 4px;
        	margin-top: 10px;
        	color: black;
        	padding: 5px;
        	padding-left: 25px;
        	font-size: 15px;
        	margin-bottom: 30px;
        }
        #infOfPay{
        	background: white;
            padding: 25px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            float: left;
            margin-left: 20px;
            height: 486px;
        }
        .orderDtails{
        	display: inline-block;
        	width: 230px;
        	text-align: right;
        }
        hr{
        	border: none;
            height: 2px;
            background-color: rgba(0, 0, 0, 0.1);
            width: 98%;
            margin: 20px auto;  
        }
        .btn{
        	display: inline-block;
            background-color: #4a6bff;
            color: white;
            border: none;
            padding: 12px 20px;
            font-size: 16px;
            border-radius: 5px;
            cursor:pointer;
            width:100%;
            transition: background-color 0.3s;
            margin-top: 50px;
        }
        #receivingAddress{
        	margin-bottom: 7px;
        }
        .btn:hover {
            background-color: #3a5bef;
        }
	</style>
</head>
<body>
	<div id="box">
		<div id="titleOfPay">
			<h1>支付订单</h1>
			<span>请填写您的信息以支付订单</span>
		</div>
		<div class="bodyOfPay">
			<h2 class="orderTitle">支付信息</h2>
			<div id="formGroup">
					<label class="typeOfInput">订单编号</label>
				    <br>
				    <input type="text" class="inputOfValue" value="${order.orderNumber }" name="orderNumber" id="orderNumber" disabled>
				    <br>
				    <label class="typeOfInput">收货手机号</label>
				    <br>
				    <input type="text" class="inputOfValue" value="${loginUser.phoneNum }" name="orderNumber" disabled>
				    <br>
				    <label class="typeOfInput">收货地址</label>
				    <br>
				    <input type="text" class="inputOfValue" name="receivingAddress" id="receivingAddress" placeholder="请输入收货地址">
				    <br>
				    <input type="checkBox" class="saveAddress" name="saveAddress">
				    <span class="saveAddress">记住地址</span>
				    <input type="submit" class="btn" id="commit" value="立即支付">
			</div>
		</div>
		<div id="infOfPay">
			<h2 class="orderTitle">订单详情</h2>
			<label>商品名称</label>
		    <span class="orderDtails">${goods.goodsName }</span>
		    <hr>
		    <label>购买数量</label>
		    <span class="orderDtails">X${order.totalQuantity }</span>
		    <hr>
		    <label>商品单价</label>
		    <span class="orderDtails">￥${goods.price }</span>
		    <hr>
		    <span class="typeOfInput">合计：￥${order.totalAmount }</span>
		</div>
	</div>
</body>
<script>
	function successOfPay(){
		var orderNumber = encodeURIComponent($("#orderNumber").val());
		var receivingAddress = $("#receivingAddress").val();
		var payButton = document.getElementById('commit');
		$.ajax({
    	    url: '/lego/changeStatus.do',
    	    type: 'POST',
    	    data: {
    	    	receivingAddress:receivingAddress,
    	    	orderNumber:orderNumber,
    	    	orderStatus:'processing',
    	    	totalQuantity:${order.totalQuantity },
    	    	goodsId:${goods.goodsId}
	        },
    	    success: function(response) {
    	    	document.getElementById('receivingAddress').disabled = true;
    			payButton.disabled = true;
    	        payButton.value = '处理中...';
    			setTimeout(function(){
    				        alert('支付成功！感谢您的购买。');
    	                    payButton.value = '支付成功';
    	                    payButton.style.backgroundColor = '#28a745';
    	                    setTimeout(function(){
    	                    	var newUrl = "/lego/index.jsp";
        	                	window.location.href = newUrl;
        	        		}, 2000);
    	        }, 2000);
    	    }
    	})
	}
	document.getElementById('commit').addEventListener("click",function(){
		if($("#receivingAddress").val()!=null&&$("#receivingAddress").val()!=""){
			successOfPay()
		}else{
			alert('请输入收货地址！');
		}
	})
</script>
</html>